package LeetcodeTest_nineteen;
//746. 使用最小花费爬楼梯

public class minCostClimbingStairs
{
    public static void main(String[] args)
    {
        int costs[]={10,15,20};
        System.out.println(Solution.minCostClimbingStairs(costs));
    }
}
class Solution
{
    public static int minCostClimbingStairs(int[] cost)
    {
        int i;
        if(cost.length==2)
            return cost[1];
        int minCost[]=new int[cost.length];
        minCost[0]=cost[0];
        minCost[1]=cost[1];
        for(i=2;i<cost.length-1;i++)
        {
            minCost[i]=Math.min(minCost[i-2]+cost[i],minCost[i-1]+cost[i]);
        }
        minCost[i]=Math.min(minCost[i-2]+cost[i],minCost[i-1]);
        return minCost[cost.length-1];
    }
}